import { observable, action } from 'mobx';
import { delevlop } from '../fetch/apisetting';

class Delevlop {
    @observable inProgress = false;
    @observable menuOne = [];
    @observable menuTwo = [];
    @observable inputInfo=[];
    @observable accessInfo = [];
    @observable safetyInfo = [];
    @observable inputNum = [];
    @observable update = [];
    @observable detail = [];   
    @observable defaultValue ='';
    @observable seviceType={
        type:0
    }
    @observable apiQueryparam={
        "serviceType":0,
        "interfaceCode":"getCountByGeoHash",
        "args":[]
    }
    @observable updataParam={
        "id":'',
        "callDesc":''
    }
    @observable detailParam={
        "id":''
    }
    @observable apiQueryparamShow={
    }
    @observable apiQueryResultShow={
    }
    @action getMenuList(){
        this.inProgress=true
        return delevlop.getMenuList({"parentId":-1}).then(
            action('getProductData',res=>{
                this.menuOne=res.data
                this.inProgress = false
            })
        )
    }
    @action getInterfacesByMenu(data={}){
        this.inProgress=true
        return delevlop.getInterfacesByMenu(data).then(
            action('getProductData',res=>{
                this.inProgress = false
                this.menuTwo=res.data
            })
        )
    }
    @action getAccessIntro(data={}){
        this.inProgress=true
        return delevlop.getAccessIntro(data).then(
            action('getProductData',res=>{
                this.inProgress = false
                this.accessInfo = JSON.parse(res.data)
            })
        )
    }
    @action getSafetyIntro(data={}){
        this.inProgress=true
        return delevlop.getSafetyIntro(data).then(
            action('getProductData',res=>{
                this.inProgress = false
                this.safetyInfo = JSON.parse(res.data)
            })
        )
    }
    @action getServiceList(){
    this.inProgress=true
    return delevlop.getServiceList(this.seviceType).then(
        action('getServiceList',res=>{
            this.inProgress = false
            if(res.errorcode==0&&res.errormsg==''){
                this.inputInfo=res.data
                this.defaultValue=res.data[0].interfaceName
            }
        })
    )
}
    @action callService(){
        this.inProgress=true
        return delevlop.callService(this.apiQueryparam).then(
            action('callService',res=>{
                this.inProgress = false
                // console.log(res.data)
                this.apiQueryResultShow=res.data
            })
        )
    }
    @action updateCall(){
        this.inProgress=true
        return delevlop.updateCall(this.updataParam).then(
            action('updateCall',res=>{
                this.inProgress = false
                console.log(res.data)
                this.detail=res.data.call_desc
            })
        )
    }
    @action getDetail(){
        this.inProgress=true
        return delevlop.getDetail(this.detailParam).then(
            action('getDetail',res=>{
                this.inProgress = false
                console.log(res.data)
                this.detail=res.data.call_desc
            })
        )
    }
}

export default new Delevlop();

